<!DOCTYPE html>

<html lang="en" data-content_root="../">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />

  <title>CheckCXXSymbolExists &mdash; CMake 4.1.1 Documentation</title>

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=a2c47e09" />
    <link rel="stylesheet" type="text/css" href="../_static/cmake.css?v=4d06bd55" />
    
    <script src="../_static/documentation_options.js?v=e6a937a4"></script>
    <script src="../_static/doctools.js?v=9bcbadda"></script>
    <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
    
    <link rel="icon" href="../_static/cmake-favicon.ico"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="CheckFortranCompilerFlag" href="CheckFortranCompilerFlag.html" />
    <link rel="prev" title="CheckCXXSourceRuns" href="CheckCXXSourceRuns.html" />
 

  </head><body>
    <input id="sidebar-check" type="checkbox" />
    <label id="sidebar-overlay" for="sidebar-check"></label>



    <div class="related relbar1" role="navigation" aria-label="Related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="CheckFortranCompilerFlag.html" title="CheckFortranCompilerFlag"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="CheckCXXSourceRuns.html" title="CheckCXXSourceRuns"
             accesskey="P">previous</a> |</li>
  <li>
    <label class="sidebar-toggle" for="sidebar-check"></label>
  </li>
  <li class="rootlink">
    <img src="../_static/cmake-logo-16.png" width="16" height="16" alt=""/>
    <a href="https://cmake.org/">CMake 4.1.1</a>
    <span class="reldelim1"> &#187;</span>
  </li>
  <li>
    <a href="../index.html">Documentation</a> &#187;
  </li>

          <li class="nav-item nav-item-1"><a href="../manual/cmake-modules.7.html" accesskey="U">cmake-modules(7)</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">CheckCXXSymbolExists</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="checkcxxsymbolexists">
<span id="module:CheckCXXSymbolExists"></span><h1>CheckCXXSymbolExists<a class="headerlink" href="#checkcxxsymbolexists" title="Link to this heading">¶</a></h1>
<p>This module provides a command to check whether a C++ symbol exists.</p>
<p>Load this module in a CMake project with:</p>
<div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="nf">include(</span><span class="nb">CheckCXXSymbolExists</span><span class="nf">)</span>
</pre></div>
</div>
<section id="commands">
<h2>Commands<a class="headerlink" href="#commands" title="Link to this heading">¶</a></h2>
<p>This module provides the following command:</p>
<dl class="cmake command">
<dt class="sig sig-object cmake" id="command:check_cxx_symbol_exists">
<span class="sig-name descname"><span class="pre">check_cxx_symbol_exists</span></span><a class="headerlink" href="#command:check_cxx_symbol_exists" title="Link to this definition">¶</a></dt>
<dd><p>Checks once whether a symbol exists as a function, variable, or preprocessor
macro in C++:</p>
<div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="nf">check_cxx_symbol_exists(</span><span class="nv">&lt;symbol&gt;</span><span class="w"> </span><span class="nv">&lt;headers&gt;</span><span class="w"> </span><span class="nv">&lt;variable&gt;</span><span class="nf">)</span>
</pre></div>
</div>
<p>This command checks whether the <code class="docutils literal notranslate"><span class="pre">&lt;symbol&gt;</span></code> is available after including
the specified header file(s) <code class="docutils literal notranslate"><span class="pre">&lt;headers&gt;</span></code>, and stores the result in the
internal cache variable <code class="docutils literal notranslate"><span class="pre">&lt;variable&gt;</span></code>.  Multiple header files can be
specified in one argument as a string using a
<a class="reference internal" href="../manual/cmake-language.7.html#cmake-language-lists"><span class="std std-ref">semicolon-separated list</span></a>.</p>
<p>If the header files define the symbol as a macro, it is considered
available and assumed to work.  If the symbol is declared as a function
or variable, the check also ensures that it links successfully
(i.e., the symbol must exist in a linked library or object file).</p>
<p>Symbols that are types, enum values, or C++ templates are not
recognized.  For those, consider using the <span class="target" id="index-0-module:CheckTypeSize"></span><a class="reference internal" href="CheckTypeSize.html#module:CheckTypeSize" title="CheckTypeSize"><code class="xref cmake cmake-module docutils literal notranslate"><span class="pre">CheckTypeSize</span></code></a> or
<span class="target" id="index-0-module:CheckSourceCompiles"></span><a class="reference internal" href="CheckSourceCompiles.html#module:CheckSourceCompiles" title="CheckSourceCompiles"><code class="xref cmake cmake-module docutils literal notranslate"><span class="pre">CheckSourceCompiles</span></code></a> module instead.</p>
<p>This command is intended to check symbols as they appear in C++.  For C
symbols, use the <span class="target" id="index-0-module:CheckSymbolExists"></span><a class="reference internal" href="CheckSymbolExists.html#module:CheckSymbolExists" title="CheckSymbolExists"><code class="xref cmake cmake-module docutils literal notranslate"><span class="pre">CheckSymbolExists</span></code></a> module instead.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>This command is unreliable for symbols that are (potentially) overloaded
functions.  Since there is no reliable way to predict whether
a given function in the system environment may be defined as an
overloaded function or may be an overloaded function on other systems
or will become so in the future, it is generally advised to use the
<span class="target" id="index-1-module:CheckSourceCompiles"></span><a class="reference internal" href="CheckSourceCompiles.html#module:CheckSourceCompiles" title="CheckSourceCompiles"><code class="xref cmake cmake-module docutils literal notranslate"><span class="pre">CheckSourceCompiles</span></code></a> module for checking any function symbol
(unless it is certain the checked function is not overloaded on other
systems or will not be so in the future).</p>
</div>
<p class="rubric">Variables Affecting the Check</p>
<p>The following variables may be set before calling this command to modify
the way the check is run:</p>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">CMAKE_REQUIRED_FLAGS</span></code></dt><dd><p>A space-separated string of additional flags to pass to the compiler.
A <a class="reference internal" href="../manual/cmake-language.7.html#cmake-language-lists"><span class="std std-ref">semicolon-separated list</span></a> will not work.
The contents of <span class="target" id="index-0-variable:CMAKE_&lt;LANG&gt;_FLAGS"></span><a class="reference internal" href="../variable/CMAKE_LANG_FLAGS.html#variable:CMAKE_&lt;LANG&gt;_FLAGS" title="CMAKE_&lt;LANG&gt;_FLAGS"><code class="xref cmake cmake-variable docutils literal notranslate"><span class="pre">CMAKE_&lt;LANG&gt;_FLAGS</span></code></a> and its associated
configuration-specific <span class="target" id="index-0-variable:CMAKE_&lt;LANG&gt;_FLAGS_&lt;CONFIG&gt;"></span><a class="reference internal" href="../variable/CMAKE_LANG_FLAGS_CONFIG.html#variable:CMAKE_&lt;LANG&gt;_FLAGS_&lt;CONFIG&gt;" title="CMAKE_&lt;LANG&gt;_FLAGS_&lt;CONFIG&gt;"><code class="xref cmake cmake-variable docutils literal notranslate"><span class="pre">CMAKE_&lt;LANG&gt;_FLAGS_&lt;CONFIG&gt;</span></code></a> variables
are automatically prepended to the compiler command before the contents of
this variable.</p>
</dd>
</dl>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">CMAKE_REQUIRED_DEFINITIONS</span></code></dt><dd><p>A <a class="reference internal" href="../manual/cmake-language.7.html#cmake-language-lists"><span class="std std-ref">semicolon-separated list</span></a> of compiler
definitions, each of the form <code class="docutils literal notranslate"><span class="pre">-DFOO</span></code> or <code class="docutils literal notranslate"><span class="pre">-DFOO=bar</span></code>.  A definition for
the name specified by the result variable argument of the check
command is also added automatically.</p>
</dd>
</dl>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">CMAKE_REQUIRED_INCLUDES</span></code></dt><dd><p>A <a class="reference internal" href="../manual/cmake-language.7.html#cmake-language-lists"><span class="std std-ref">semicolon-separated list</span></a> of header
search paths to pass to the compiler.  These will be the only header
search paths used; the contents of the <span class="target" id="index-0-prop_dir:INCLUDE_DIRECTORIES"></span><a class="reference internal" href="../prop_dir/INCLUDE_DIRECTORIES.html#prop_dir:INCLUDE_DIRECTORIES" title="INCLUDE_DIRECTORIES"><code class="xref cmake cmake-prop_dir docutils literal notranslate"><span class="pre">INCLUDE_DIRECTORIES</span></code></a>
directory property will be ignored.</p>
</dd>
</dl>
<dl>
<dt><code class="docutils literal notranslate"><span class="pre">CMAKE_REQUIRED_LINK_OPTIONS</span></code></dt><dd><div class="versionadded">
<p><span class="versionmodified added">Added in version 3.14.</span></p>
</div>
<p>A <a class="reference internal" href="../manual/cmake-language.7.html#cmake-language-lists"><span class="std std-ref">semicolon-separated list</span></a> of options to
add to the link command (see <span class="target" id="index-0-command:try_compile"></span><a class="reference internal" href="../command/try_compile.html#command:try_compile" title="try_compile"><code class="xref cmake cmake-command docutils literal notranslate"><span class="pre">try_compile()</span></code></a> for further details).</p>
</dd>
</dl>
<dl class="simple">
<dt><code class="docutils literal notranslate"><span class="pre">CMAKE_REQUIRED_LIBRARIES</span></code></dt><dd><p>A <a class="reference internal" href="../manual/cmake-language.7.html#cmake-language-lists"><span class="std std-ref">semicolon-separated list</span></a> of libraries to
add to the link command.  These can be the names of system libraries, or
they can be <a class="reference internal" href="../manual/cmake-buildsystem.7.html#imported-targets"><span class="std std-ref">Imported Targets</span></a> (see <span class="target" id="index-1-command:try_compile"></span><a class="reference internal" href="../command/try_compile.html#command:try_compile" title="try_compile"><code class="xref cmake cmake-command docutils literal notranslate"><span class="pre">try_compile()</span></code></a> for further
details).</p>
</dd>
</dl>
<dl>
<dt><code class="docutils literal notranslate"><span class="pre">CMAKE_REQUIRED_LINK_DIRECTORIES</span></code></dt><dd><div class="versionadded">
<p><span class="versionmodified added">Added in version 3.31.</span></p>
</div>
<p>A <a class="reference internal" href="../manual/cmake-language.7.html#cmake-language-lists"><span class="std std-ref">semicolon-separated list</span></a> of library search
paths to pass to the linker (see <span class="target" id="index-2-command:try_compile"></span><a class="reference internal" href="../command/try_compile.html#command:try_compile" title="try_compile"><code class="xref cmake cmake-command docutils literal notranslate"><span class="pre">try_compile()</span></code></a> for further
details).</p>
</dd>
</dl>
<dl>
<dt><code class="docutils literal notranslate"><span class="pre">CMAKE_REQUIRED_QUIET</span></code></dt><dd><div class="versionadded">
<p><span class="versionmodified added">Added in version 3.1.</span></p>
</div>
<p>If this variable evaluates to a boolean true value, all status messages
associated with the check will be suppressed.</p>
</dd>
</dl>
</dd></dl>

</section>
<section id="examples">
<h2>Examples<a class="headerlink" href="#examples" title="Link to this heading">¶</a></h2>
<p>The following example demonstrates how to check for the presence of a
preprocessor macro <code class="docutils literal notranslate"><span class="pre">SEEK_SET</span></code> and the C++ function <code class="docutils literal notranslate"><span class="pre">std::fopen()</span></code> from
the <code class="docutils literal notranslate"><span class="pre">&lt;cstdio&gt;</span></code> header using this module:</p>
<div class="highlight-cmake notranslate"><div class="highlight"><pre><span></span><span class="nf">include(</span><span class="nb">CheckCXXSymbolExists</span><span class="nf">)</span>

<span class="c"># Check for macro SEEK_SET</span>
<span class="nf">check_cxx_symbol_exists(</span><span class="no">SEEK_SET</span><span class="w"> </span><span class="s">&quot;cstdio&quot;</span><span class="w"> </span><span class="no">HAVE_SEEK_SET</span><span class="nf">)</span>

<span class="c"># Check for function std::fopen</span>
<span class="nf">check_cxx_symbol_exists(</span><span class="nb">std</span><span class="o">::</span><span class="nb">fopen</span><span class="w"> </span><span class="s">&quot;cstdio&quot;</span><span class="w"> </span><span class="no">HAVE_STD_FOPEN</span><span class="nf">)</span>
</pre></div>
</div>
</section>
<section id="see-also">
<h2>See Also<a class="headerlink" href="#see-also" title="Link to this heading">¶</a></h2>
<ul class="simple">
<li><p>The <span class="target" id="index-1-module:CheckSymbolExists"></span><a class="reference internal" href="CheckSymbolExists.html#module:CheckSymbolExists" title="CheckSymbolExists"><code class="xref cmake cmake-module docutils literal notranslate"><span class="pre">CheckSymbolExists</span></code></a> module to check whether a C symbol exists.</p></li>
</ul>
</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="Main">
        <div class="sphinxsidebarwrapper">
  <div>
    <h3>Table of Contents</h3>
    <ul>
<li><a class="reference internal" href="#">CheckCXXSymbolExists</a><ul>
<li><a class="reference internal" href="#commands">Commands</a></li>
<li><a class="reference internal" href="#examples">Examples</a></li>
<li><a class="reference internal" href="#see-also">See Also</a></li>
</ul>
</li>
</ul>

  </div>
  <div>
    <h4>Previous topic</h4>
    <p class="topless"><a href="CheckCXXSourceRuns.html"
                          title="previous chapter">CheckCXXSourceRuns</a></p>
  </div>
  <div>
    <h4>Next topic</h4>
    <p class="topless"><a href="CheckFortranCompilerFlag.html"
                          title="next chapter">CheckFortranCompilerFlag</a></p>
  </div>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../_sources/module/CheckCXXSymbolExists.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<search id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</search>
<script>document.getElementById('searchbox').style.display = "block"</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="Related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="CheckFortranCompilerFlag.html" title="CheckFortranCompilerFlag"
             >next</a> |</li>
        <li class="right" >
          <a href="CheckCXXSourceRuns.html" title="CheckCXXSourceRuns"
             >previous</a> |</li>
  <li>
    <label class="sidebar-toggle" for="sidebar-check"></label>
  </li>
  <li class="rootlink">
    <img src="../_static/cmake-logo-16.png" width="16" height="16" alt=""/>
    <a href="https://cmake.org/">CMake 4.1.1</a>
    <span class="reldelim1"> &#187;</span>
  </li>
  <li>
    <a href="../index.html">Documentation</a> &#187;
  </li>

          <li class="nav-item nav-item-1"><a href="../manual/cmake-modules.7.html" >cmake-modules(7)</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">CheckCXXSymbolExists</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
    &#169; Copyright 2000-2025 Kitware, Inc. and Contributors.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.1.3.
    </div>
<script type="text/javascript">
(function() {
  "use strict";
  const hide = () => document.getElementById("sidebar-check").checked = false;
  addEventListener("keydown", e => (e.key === "Escape") && hide());
  addEventListener("click", e => (e.target.tagName === "A") && hide());
  addEventListener("hashchange", hide)
})();
</script>
  </body>
</html>